1. Field of the Invention
The present invention relates to sorting data records and more particularly to a system and method for inputing data to a sort utility from a user program.
2. Description of the Related Art
The process of sorting data records using a digital computer generally involves the reading of unordered data into memory from external storage media, ordering the records into a specified sequence, and writing the records to external storage media. In many cases, the reading and writing of the data records from and to external media is done by the sort utility itself. There are occasions when another user program or routine may be used to read and/or write the data. The user program or routine may be used for a number of different reasons. Among these reasons are: (1) record selection, (2) record content editing, (3) obtaining records from a source that the sort utility is not capable of reading.
Typically, sorting requires a large amount of computer resources in the form of memory and computer time. Another resource is elapsed time, or the time that transpires from the start of the process to the end of the process.
One current prior art process by which a user program provides input data to a sort utility uses a record level interface between a user written program called an E15 routine and the sort utility. Within the IBM mainframe environment, this interface is known as the E15 interface. Within the E15 interface, the E15 routine is responsible for the reading of the data from an external storage medium, if any, and/or the dynamic creation of the data to be sorted by the sort utility.
The E15 interface algorithm is described in further detail in FIG. 1. As shown in step 101 of FIG. 1, the user program allocates buffers for use in reading data from an external medium. In doing so, the user program logically connects the external media with the user program and/or E15 routine. One common alternative is to delay the allocation of buffers and logical connection of the external medium until the first call by the sort utility to the E15 routine in step 104.
In step 102, the user program invokes the sort utility. In invoking the sort utility, the user program builds a set of parameters, then passes the set of parameters to the sort utility. One of the parameters in the set of parameters is the address of the routine responsible for presenting data to the sort, also known as the E15 routine. The E15 routine may be part of the user program or it may be a separate program unto itself. Additional parameters may include: the parts of the record to be used as sort keys and the desired sort sequence (i.e., ascending or descending).
In step 103, the sort utility performs initialization. Typically, initialization includes memory allocation for various purposes. One allocated memory area may be referred to as the record save area (RSA). The RSA is intended to hold data records passed to the sort utility from the user program. Another allocated memory area may be referred to as the key save area (KSA). A given KSA generally includes: (1) a pointer to a subsequent KSA entry, (2) extracted sort keys, (3) a pointer back to the input data record. The sort utility determines an optimum size of the memory to be used to hold RSA and/or KSA.
In step 104, the sort utility requests the next record. In order to process the next record, the sort utility calls the E15 routine requesting a pointer to the next record. The E15 routine, in locating the pointer to the next record, may cause other processes to be invoked that will load additional data into the buffers allocated by the user program from the external storage. If the invocation of these other processes by the E15 routine is not well coordinated with the overall processing of the sort utility, significant elapsed time delays may result. Due to this lack of coordination of optimization or I/O processing between the sort utility and the E15 routine, there is a very high likelihood of time delays.
In step 105, the sort utility checks that a record is presented. In the case where a record is retrieved, processing continues with step 106. A null pointer indicates the end of input processing.
In step 106, the sort utility moves the data record pointed to by the E15 routine into the RSA. In moving the data to the RSA, the sort utility may need to buffer and/or move records out of the RSA and write the records to external storage media. This writing may be either synchronous or asynchronous with other operations of the sort utility, but is typically not coordinated with the E15 routine.
The sort utility extracts the sort keys used for ordering the data from the data record and places the generated key and the pointer to the original record in the KSA. The functions of the RSA and KSA may be merged into the RSA by making the RSA entry large enough to hold a pointer to the next RSA entry and the extracted sort keys, along with the input data record. Once the data is loaded in a predetermined structure (e.g., RSA and/or KSA) in memory, the actual sorting routine sorts the data. The sort utility may use any sort routine desired.
At the end of step 106, processing goes back to step 104.
For the foregoing reasons, there is a need for an improved system and method for inputing data to a sort utility from a user program such that time delays are minimized.